//
//  OrderListCtl.m
//  dealData
//
//  Created by  Mac on 2021/3/25.
//

#import "OrderListCtl.h"
#import "GMTOurOrderModel.h"
#import "OrderGoodsEntityList.h"
#import "GMTOurStoreCell.h"

@interface OrderListCtl ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,assign)NSInteger page;
@end

@implementation OrderListCtl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.rowHeight = 181.0;
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
   
    GMTOurOrderModel * model = self.dataArray[indexPath.row];;
    OrderGoodsEntityList * entityModel = model.orderGoodsEntityList.firstObject;
    NSString * orderId = model.moId.isNotBlankString ? model.moId :entityModel.orderId;
    NSLog(@"根据订单号orderId = %@ 来展示订单详情",orderId);
    
 
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    GMTOurStoreCell *cell = [GMTOurStoreCell cellWithTableView:tableView];
    
    GMTOurOrderModel * model = self.dataArray[indexPath.row];
    
    WS(weakSelf)
    WeakObject(cell, weakCell)
    cell.OurOrderBlock = ^(OurOrderBlockType status) {
        [weakSelf dealWithStatus:status andModel:weakCell.model];
    };
    
    if (self.dataArray.count > 0) {
        cell.model = model;
    }
    
    return cell;
}

-(void)dealWithStatus:(OurOrderBlockType)status andModel:(GMTOurOrderModel *)model {
    OrderGoodsEntityList * entityModel = model.orderGoodsEntityList.firstObject;
    NSString * orderId = model.moId.isNotBlankString ? model.moId :entityModel.orderId;
    NSLog(@"根据订单号orderId = %@ 来处理一些点击事件",orderId);
    switch (status) {
        case GMTOurStoreAction_RefundMoney:{

        }
            break;
        case GMTOurStoreAction_ReceiptGoods:{

        }
            break;
        case GMTOurStoreAction_BuyAgain:{

        }
            break;
        case GMTOurStoreAction_Pay:{

        }
            break;
        case GMTOurStoreAction_CloseOrder:{

        }
            break;
        case GMTOurStoreAction_AfterSale:{

        }
            break;
        case GMTOurStoreAction_WaitBackMoney:{
            
        }
            break;
        case GMTOurStoreAction_DidBackMoney:{
            
        }
            break;
        default:
            break;
    }
}


@end
